package com.zy.explore.handler;

import ch.qos.logback.classic.pattern.ClassicConverter;
import ch.qos.logback.classic.spi.ILoggingEvent;

import java.net.InetAddress;
import java.net.UnknownHostException;

/**
 * description Logback记录IP配置
 *
 * @author ZY
 * @date 2021-05-05 18:04
 */
public final class LogIpHandler extends ClassicConverter {

    private static final String HOST_NAME;

    static {
        try {
            HOST_NAME = InetAddress.getLocalHost().getHostAddress();
        } catch (UnknownHostException e) {
            throw new IllegalStateException(e);
        }
    }

    @Override
    public String convert(ILoggingEvent event) {
        return HOST_NAME;
    }
}
